-
Notifications
You must be signed in to change notification settings - Fork 745
/
ExportController.cs
78 lines (72 loc) · 3.42 KB
/
ExportController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace Dnn.ExportImport.Components.Controllers
{
using System.IO;
using Dnn.ExportImport.Components.Common;
using Dnn.ExportImport.Components.Dto;
using Dnn.ExportImport.Components.Entities;
using Dnn.ExportImport.Components.Providers;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
using Newtonsoft.Json;
/// <summary>The export controller.</summary>
public class ExportController : BaseController
{
/// <summary>Queues an export operation.</summary>
/// <param name="userId">The user ID.</param>
/// <param name="exportDto">The export DTO.</param>
/// <returns>The job ID.</returns>
public int QueueOperation(int userId, ExportDto exportDto)
{
exportDto.ProductSku = DotNetNuke.Application.DotNetNukeContext.Current.Application.SKU;
exportDto.ProductVersion = Globals.FormatVersion(DotNetNuke.Application.DotNetNukeContext.Current.Application.Version, true);
var dbTime = DateUtils.GetDatabaseUtcTime();
exportDto.ToDateUtc = dbTime.AddMilliseconds(-dbTime.Millisecond);
var directory = dbTime.ToString("yyyy-MM-dd_HH-mm-ss");
if (exportDto.ExportMode == ExportMode.Differential)
{
exportDto.FromDateUtc = this.GetLastJobTime(exportDto.PortalId, JobType.Export);
}
var dataObject = JsonConvert.SerializeObject(exportDto);
exportDto.IsDirty = false; // This should be set to false for new job.
var jobId = DataProvider.Instance()
.AddNewJob(
exportDto.PortalId,
userId,
JobType.Export,
exportDto.ExportName,
exportDto.ExportDescription,
directory,
dataObject);
// Run the scheduler if required.
if (exportDto.RunNow)
{
EntitiesController.Instance.RunSchedule();
}
this.AddEventLog(exportDto.PortalId, userId, jobId, Constants.LogTypeSiteExport);
return jobId;
}
/// <summary>Creates a package manifest.</summary>
/// <param name="exportJob">The export job.</param>
/// <param name="exportFileInfo">The export file info.</param>
/// <param name="summary">The summary.</param>
public void CreatePackageManifest(ExportImportJob exportJob, ExportFileInfo exportFileInfo, ImportExportSummary summary)
{
var filePath = Path.Combine(ExportFolder, exportJob.Directory, Constants.ExportManifestName);
var portal = PortalController.Instance.GetPortal(exportJob.PortalId);
var packageInfo = new ImportPackageInfo
{
Summary = summary,
PackageId = exportJob.Directory,
Name = exportJob.Name,
Description = exportJob.Description,
ExporTime = exportJob.CreatedOnDate,
PortalName = portal?.PortalName,
};
Util.WriteJson(filePath, packageInfo);
}
}
}